package sword;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 海琳琦
 * @Date: 2022/5/29 21:35
 * https://leetcode.cn/problems/yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof/
 */
public class Title62 {

    public static int lastRemaining(int n, int m) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(i);
        }
        //删除位置的索引
        int size = list.size();
        int i = 0;
        while (size != 1) {
            i = (i + m - 1) % size;
            list.remove(i);
            size--;
        }
        return list.get(0);
    }

    public static void main(String[] args) {
        lastRemaining(5, 3);
    }
}
